<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Security-Policy" content="connect-src http://example.com">
</head>
<body>
    <script src="../../resources/js-test.js"></script>
    <script>
        description("This tests that exceptions thrown by XHR.open() have reasonable messages.");

        var xhrException;
        try {
            var xhr = new XMLHttpRequest();
            xhr.open("TRACE", "http://example.com/");
            testFailed("xhr.open should throw an exception with a forbidden method type.");
        } catch (e) {
            xhrException = e;
            shouldBeEqualToString("xhrException.message", "Failed to execute 'open' on 'XMLHttpRequest': 'TRACE' HTTP method is unsupported.");
        }

        var badString = { toString: function() { throw "Exception in toString()"; } };
        var xhr = new XMLHttpRequest();
        shouldBe("xhr.readyState", "XMLHttpRequest.UNSENT");
        shouldThrow("xhr.open('GET', 'resources/xmlhttprequest-get-data.xml', true, badString, 'password');", "'Exception in toString()'");
        shouldBe("xhr.readyState", "XMLHttpRequest.UNSENT");
        shouldThrow("xhr.open('GET', 'resources/xmlhttprequest-get-data.xml', true, 'username', badString);", "'Exception in toString()'");
        shouldBe("xhr.readyState", "XMLHttpRequest.UNSENT");
    </script>
</body>
</html>
